package jdbc;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

public class RegDemo1 {
    public static void main(String[] args) {
        UserInfo userInfo = InputUtil.getInputObject(new UserInfo(), "欢迎注册", "注册");
        System.out.println(userInfo);
        try (Connection conn = DBUtil.getConnection()) {
            Statement stmt = conn.createStatement();

            String sql = "INSERT INTO userinfo(username,password,nickname,age) " +
                    "VALUES('" + userInfo.getUsername() + "','" + userInfo.getPassword() + "','" + userInfo.getNickname() + "'," + userInfo.getAge() + ")";

            System.out.println(sql);
            int count = stmt.executeUpdate(sql);
            if (count > 0) {
                System.out.println("注册成功");
            }

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
